package com.cyt.web.controller.sys;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.sys.model.po.SysVersion;
import com.cyt.sys.model.vo.SysVersionVo;
import com.cyt.sys.service.SysVersionService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by sunli on 2019/4/3.
 */

@RestController
public class SysVersionController extends SysBaseController {

    @Resource
    private SysVersionService sysVersionService;


    /**
     * 系统模块统一跳转处理
     *
     * @param model
     * @return
     */
    @RequestMapping("/sys/version/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * 版本分页查询
     *
     * @param sysVersionVo
     * @param limit
     * @param page
     * @return VersionMessage
     * @author sunli
     * @date 2019-04-10
     */
    @BaseLog(module = "系统模块", classz = "版本管理", methods = "分页查询", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysVersion/fingPager", method = RequestMethod.POST)
    public ReturnResult page(SysVersionVo sysVersionVo, int limit, int page) {
        ReturnResult VersionMessage = sysVersionService.page(sysVersionVo, limit, page);
        return VersionMessage;
    }


    /**
     * 保存or更新数据
     *
     * @param sysVersionVo
     * @return VersionMessage
     * @author sunli
     * @date 2019-04-08
     */
    @BaseLog(module = "系统模块", classz = "", methods = "保存更新/版本", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysVersion/saveOrUpdate", method = RequestMethod.POST)
    public ReturnResult saveOrUpdateVsersion(SysVersionVo sysVersionVo) {
        ReturnResult VersionMessage = sysVersionService.saveOrUpdate(sysVersionVo);
        return VersionMessage;
    }

    /**
     * 根据id删除版本信息
     *
     * @param id 版本信心id
     * @return ReturnResult
     * @author sunli
     * @date 2019-04-09
     */
    @BaseLog(module = "系统模块", classz = "版本管理", methods = "删除版本", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/sysVersion/delete", method = RequestMethod.GET)
    public ReturnResult deleteVersion(String id) {
        return sysVersionService.delete(id);
    }


    /**
     * 跳转编辑页面
     *
     * @param id 版本信息的id
     * @return view
     * @author sunli
     * @data 2019-04-09
     */
    @RequestMapping(value = "/sysVersion/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id) {
        ModelAndView view = new ModelAndView("sys/version/sysVersionEdit");
        if (id != null && !"".equals(id)) {
            SysVersion version = sysVersionService.selectVersionById(id);
            view.addObject(version);
        }
        return view;
    }

    /**
     * 获取所有版本的信息
     *
     * @param dictTypes 版本状态
     * @return VersionMessage
     * @author sunli
     * @data 2019-04-09
     */
    @RequestMapping(value = "/baseVersion/getAllVersion", method = RequestMethod.POST)
    public ReturnResult getVersionList(String dictTypes) {
        ReturnResult VersionMessage = sysVersionService.getVersionList(dictTypes);
        return VersionMessage;
    }
}

